﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GetHighScores : MonoBehaviour {
	string url="http://fischkoder.zz.mu/display.php";
	public GameObject names;
	public GameObject fishes;
	
	void Start(){
		StartCoroutine(getScore());
	}
	
	IEnumerator getScore() {
		WWW p = new WWW(url);
		yield return p;
		if(p.error != null) {
			print("There was an error posting the high score: " + p.error);
		}else{
			string[] res = p.text.Split("\n"[0]);
			for (int i = 0; i<res.Length-1; i++){
				string[] line = res[i].Split("\t"[0]);
				names.GetComponent<Text>().text += line[0]+"\n";
				fishes.GetComponent<Text>().text += line[1]+"\n";
			}
			for (int j = 0; j<10-res.Length; j++){
				names.GetComponent<Text>().text += "\n";
				fishes.GetComponent<Text>().text += "\n";
			}
		}
	}
	
	public void GoBack(){
		Application.LoadLevel(0);
	}
}
